package sdk.webview.fmc.com.fmcsdk.util;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import sdk.webview.fmc.com.fmcsdk.R;


public class ToastUtils {

        public static void showShort(Context context, String s) {
            Toast  toast = Toast.makeText(context, "", Toast.LENGTH_SHORT);//吐司信息设为空
            toast.setText(s);//只需在这设置吐司信息即可解决
            toast.show();
        }


        public static void showCustomToast(Context context, int resId, String value){

            // 创建自定义 Toast
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.custom_toast, null);

            // 获取自定义布局中的控件
            ImageView imageView = layout.findViewById(R.id.toast_icon);
            TextView textView = layout.findViewById(R.id.toast_text);

            // 设置文本和图标
            textView.setText(value);
            imageView.setImageResource(resId);  // 设置你需要的图标资源


            Toast toast = Toast.makeText(context,"",Toast.LENGTH_SHORT);
            toast.setDuration(Toast.LENGTH_SHORT);  // 设置显示时间
            toast.setGravity(Gravity.CENTER, 0, 0);  // 设置显示位置为屏幕中间
            toast.setText(value);

            toast.setView(layout);  // 设置自定义布局

            // 显示 Toast
            toast.show();
        }

}
